package com.xiaominfo.oss.filter;

import com.xiaominfo.oss.common.pojo.ThreadLocalHolder;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Author lien
 * @Date 2019/12/24 16:45
 * @Description GlobalRequestMappingFilter
 * 			全局请求拦截器
 **/
public class GlobalRequestMappingFilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		
	}


	/**
	 * 把所有请求的request放入到缓存中（目标，后面什么时候用的时候能取出来）
	 * @param request
	 * @param response
	 * @param chain
	 * @throws IOException
	 * @throws ServletException
	 */
	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req=(HttpServletRequest)request;
		ThreadLocalHolder.setRequest(req);
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
		
	}

}
